package com.simple.common.utils.ExcelUtil;

import lombok.Data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description 存放需要导出的动态数据
 */
@Data
public class DynamicDataMapping {

    private String dataId;
    private List<Map<String, Object>> dataList;


    /**
     * @description: 组装只有一个list类型的动态数据
     * @param dataId
     * @param dataList
     * @return java.util.List<com.liu.susu.excel.template.poi.common.DynamicDataMapping>
     */
    public static List<DynamicDataMapping> createOneDataList(String dataId, List<Map<String, Object>> dataList) {
        if (dataList == null)
            return null;
        return Collections.singletonList(getDynamicDataMapping(dataId,dataList));
    }

    /**
     * @description: 组装只有多个list类型的动态数据
     * @param transMap
     * @return java.util.List<com.liu.susu.excel.template.poi.common.DynamicDataMapping>
     */
    public static List<DynamicDataMapping> createMorDataList(Map<String,List<Map<String, Object>>> transMap) {
        if (transMap == null)
            return null;
        List<DynamicDataMapping> list = new ArrayList<>();
        transMap.forEach((dataId,dataList)->{
            list.add(getDynamicDataMapping(dataId,dataList));
        });
        return list;
    }

    public static DynamicDataMapping getDynamicDataMapping(String dataId, List<Map<String, Object>> dataList){
        DynamicDataMapping dynamicData = new DynamicDataMapping();
        dynamicData.dataId = dataId;
        dynamicData.dataList = dataList;
        return dynamicData;
    }

}


